package com.mdd.product.controller;

import com.mdd.common.aop.Log;
import com.mdd.common.aop.NotPower;
import com.mdd.common.core.AjaxResult;
import com.mdd.common.validate.IdValidate;
import com.mdd.product.service.IProductPropertyValueService;
import com.mdd.product.validate.ProductPropertyValueCreateValidate;
import com.mdd.product.validate.ProductPropertyValueUpdateValidate;
import com.mdd.product.vo.ProductPropertyValueDetailVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("api/propertyValue")
@Api(tags = "商品属性值管理")
public class ProductPropertyValueController {

    @Resource
    IProductPropertyValueService iProductPropertyValueService;
    @NotPower

    @Log(title = "商品属性值新增")
    @PostMapping("/add")
    @ApiOperation(value="商品属性值新增")
    public AjaxResult<Object> add(@Validated @RequestBody ProductPropertyValueCreateValidate createValidate) {
        iProductPropertyValueService.add(createValidate);
        return AjaxResult.success();
    }

    @NotPower
    @Log(title = "商品属性值列表")
    @PostMapping("/listByPropertyId")
    @ApiOperation(value="商品属性值列表")
    public AjaxResult<List<ProductPropertyValueDetailVo>> listBySpuId(@Validated @RequestBody IdValidate propertyId) {
        return AjaxResult.success( iProductPropertyValueService.list(propertyId.getId()));
    }
    @NotPower
    @Log(title = "商品属性值编辑")
    @PostMapping("/edit")
    @ApiOperation(value="商品属性值编辑")
    public AjaxResult<Object> edit(@Validated @RequestBody ProductPropertyValueUpdateValidate updateValidate) {
        iProductPropertyValueService.edit(updateValidate);
        return AjaxResult.success();
    }

    @NotPower
    @Log(title = "商品属性值删除")
    @PostMapping("/del")
    @ApiOperation(value="商品属性值删除")
    public AjaxResult<Object> del(@Validated @RequestBody IdValidate idValidate) {
        iProductPropertyValueService.del(idValidate.getId());
        return AjaxResult.success();
    }

}
